package com.biyabi.service.impl;

import com.biyabi.dao.AdminMapper;
import com.biyabi.entity.Admin;
import com.biyabi.entity.AdminExample;
import com.biyabi.service.AdminService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminMapper adminMapper;
    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
    public Admin login(Admin admin) {
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria().andPasswordEqualTo(admin.getPassword());
        adminExample.createCriteria().andUsernameEqualTo(admin.getUsername());
        List<Admin> admins = adminMapper.selectByExample(adminExample);
        if(admins.size()>0)
            return admins.get(0);
        else
            return null;
    }
}
